package com.klhappy.houyuan.adapter;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.activity.Food_StampActivity;
import com.klhappy.houyuan.bean.FoodStampBean.StampBean;
import com.klhappy.houyuan.bean.FoodsStamp.Records;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.utils.NotifyMethod;
import com.klhappy.houyuan.view.ImageManager;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FoodStampAdapter extends BaseAdapter {

    private List<StampBean> stampBeans;
    private Context mContext;

    public FoodStampAdapter(Context context, List<StampBean> stampBeans) {
        this.stampBeans = stampBeans;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return stampBeans.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return stampBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_stamp, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ImageManager.loadImagex(UrlConstant.BASE_URL + stampBeans.get(position).getIcon(), holder.ivFs);
        String time = stampBeans.get(position).getExp_date().substring(0, 10);
//        holder.tv_stamp.setText(stampBeans.get(position).getFoodsType());
        holder.tvMoney.setText("￥  " + stampBeans.get(position).getMoney());
        holder.tvDate.setText(time + "前使用");
        holder.tvDetail.setText(stampBeans.get(position).getRule_desc());
        if (stampBeans.get(position).getStatus().equals("1")){
            holder.tv_use.setTextColor(Color.parseColor("#869e34"));
            holder.tv_use.setText("可使用");
        }else {
            holder.tv_use.setTextColor(Color.parseColor("#c9c9c9"));
            holder.tv_use.setText("已过期");
        }
        return convertView;
    }


    static class ViewHolder {
        @InjectView(R.id.iv_food_stamp)
        ImageView ivFs;
        @InjectView(R.id.tv_money)
        TextView tvMoney;
        @InjectView(R.id.tv_data)
        TextView tvDate;
        @InjectView(R.id.tv_detail)
        TextView tvDetail;
        @InjectView(R.id.tv_stamp)
        TextView tv_stamp;
        @InjectView(R.id.tv_use)
        TextView tv_use;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

}
